﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using AChance.Bll.Func;
using AChance.Dal.Entity;
using AChance.Dal.Func;
using AChance.Func;
using StackExchange.Redis;

namespace AChance.Bll.Trans
{
    public partial class TrnRedis
    {
        /// <summary>
        /// 创建Redis用户
        /// </summary>
        [BllTrans(LockMode = FunLock.Mode.Distributed, SqlOperMode = DalConst.SqlOperMode.None)]
        public partial class AddUser
        {
            public static void Exec()
            {
                #region 操作执行
                for (int index = 1; index <= 99; index++)
                {
                    var no = index.ToString("00");
                    if (FunRedis.Db.Users.StringSet(no, string.Empty, TimeSpan.FromMinutes(20), When.NotExists))
                    {
                        FunRedis.User.No = no;
                        return;
                    }
                }
                throw new Exception("创建Redis用户失败");
                #endregion
            }
        }
        /// <summary>
        /// 更新Redis用户期限
        /// </summary>
        [BllTrans(SqlOperMode = DalConst.SqlOperMode.None)]
        public partial class ChgUserExpiry
        {
            public static void Exec()
            {
                #region 操作执行
                if (!FunRedis.Db.Users.StringSet(FunRedis.User.No, string.Empty, TimeSpan.FromMinutes(20), When.Exists))
                    throw new Exception("Redis用户丢失");
                #endregion
            }
        }
    }
}
